package com.ssm.mq.service;

import com.ssm.mq.config.AmqpConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * @see RabbitListener 标注在类上面表示当有收到消息的时候，就交给 @RabbitHandler 的方法处理
 * 具体使用哪个方法处理，根据 MessageConverter 转换后的参数类型
 */
@Slf4j
@Service
@RabbitListener(queues = AmqpConfig.QUEUE_NAME_ANONYMOUS)
public class AmqpConsumerClass {
    @RabbitHandler
    public void receive1(Integer message) {
        log.info(AmqpConfig.QUEUE_NAME_ANONYMOUS + " Integer: " + message);
    }

    @RabbitHandler
    public void receive2(byte[] message) {
        log.info(AmqpConfig.QUEUE_NAME_ANONYMOUS + " byte[]: " + new String(message));
    }

    @RabbitHandler
    public void receive2(String message) {
        log.info(AmqpConfig.QUEUE_NAME_ANONYMOUS + " String: " + message);
    }
}